package com.cnzhizi.wheelpop.activity;

import com.cnzhizi.wheelpop.R;
import com.cnzhizi.wheelpop.model.TwoModel;
import com.cnzhizi.wheelpop.model.ThreeModel;
import com.cnzhizi.wheelpop.model.OneModel;
import com.cnzhizi.wheelpop.ui.SkmDatePickerPopup;
import com.cnzhizi.wheelpop.ui.SkmModiPopup;

import android.os.Bundle;
import android.app.Activity;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;


public class MainActivity extends Activity {


    /**
     * 所有一级  内含所有数据
     */
    List<OneModel> oneModelList = new ArrayList<OneModel>();

    public SkmModiPopup skmModiPopup;
    public SkmDatePickerPopup skmDatePickerPopup;
    public Button showpop;
    public Button showtime;
    public EditText editText;
    public EditText editText2;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_my);






        initData();


        editText= (EditText) findViewById(R.id.editText);
        editText2= (EditText) findViewById(R.id.editText2);
        showpop= (Button)findViewById(R.id.showpop);
        showtime= (Button)findViewById(R.id.showtime);

        showpop.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
              //  popupHandler.sendEmptyMessageDelayed(0, 1000);
                skmModiPopup = new SkmModiPopup(MainActivity.this, skmPopOnClickListener,oneModelList,editText2.getText().toString(),Integer.parseInt(editText.getText().toString()),editText);
                skmModiPopup.showAtLocation(findViewById(R.id.all),
                        Gravity.BOTTOM| Gravity.CENTER_HORIZONTAL, 0, 0);
            }
        });
        showtime.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                //  popupHandler.sendEmptyMessageDelayed(0, 1000);
                skmDatePickerPopup = new SkmDatePickerPopup(MainActivity.this, skmDatePickerPopupOnClickListener, editText2.getText().toString(),editText);
                skmDatePickerPopup.showAtLocation(findViewById(R.id.all),
                        Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
            }
        });

    }

    private void initData() {
        //数据格式要求，二三级都必须有数据 可用空值代替
        //假数据 1

        OneModel oneModel1 = new OneModel();
        oneModel1.setId("1");
        oneModel1.setName("山东");




        //假数据 2
        List<TwoModel> twoModelList2 = new ArrayList<TwoModel>();
        OneModel oneModel2 = new OneModel();
        oneModel2.setId("1");
        oneModel2.setName("河北");

        TwoModel twoModel2 = new TwoModel();
        twoModel2.setId("4");
        twoModel2.setName("某地");

        TwoModel twoModel3 = new TwoModel();
        twoModel3.setId("5");
        twoModel3.setName("哈哈");

        List<ThreeModel> threeModelList = new ArrayList<ThreeModel>();
        ThreeModel threeModel = new ThreeModel();
        threeModel.setId("6");
        threeModel.setName("哈哈的下一级");
        threeModelList.add(threeModel);

        twoModel3.setThreeModelList(threeModelList);


        twoModelList2.add(twoModel2);
        twoModelList2.add(twoModel3);


        oneModel2.setTwoModelList(twoModelList2);

for (int i=0;i<20;i++){
    OneModel oneModelt = new OneModel();
    oneModelt.setId(i+"");
    oneModelt.setName("山东"+i);

    List<TwoModel> twoModelListT = new ArrayList<TwoModel>();
    TwoModel twoModelt = new TwoModel();
    twoModelt.setId(""+i);
    twoModelt.setName('A' +i+"");
    twoModelListT.add(twoModelt);

    List<ThreeModel> threeModelListT = new ArrayList<ThreeModel>();
    ThreeModel threeModelT = new ThreeModel();
    threeModelT.setId(""+i);
    threeModelT.setName("你好"+i);
    threeModelList.add(threeModelT);

       twoModelt.setThreeModelList(threeModelList);

        oneModelt.setTwoModelList(twoModelListT);

    oneModelList.add(oneModelt);
}


        oneModelList.add(oneModel1);
        oneModelList.add(oneModel2);

    }


    public SkmModiPopup.SkmPopOnClickListener skmPopOnClickListener=new SkmModiPopup.SkmPopOnClickListener(){

        @Override
        public void myOnClick(int pOneCurrent, int pTwoCurrent, int pThreeCurrent, View v,View vv) {
              skmModiPopup.dismiss();

            Toast.makeText(MainActivity.this, "一级：id:" + oneModelList.get(pOneCurrent).getId() + " name:" + oneModelList.get(pOneCurrent).getName()+ " 二级：id" + oneModelList.get(pOneCurrent).getTwoModelList().get(pTwoCurrent).getId() + "name:" + oneModelList.get(pOneCurrent).getTwoModelList().get(pTwoCurrent).getName() + " 三级：id" + oneModelList.get(pOneCurrent).getTwoModelList().get(pTwoCurrent).getThreeModelList().get(pThreeCurrent).getId() + "name:" + oneModelList.get(pOneCurrent).getTwoModelList().get(pTwoCurrent).getThreeModelList().get(pThreeCurrent).getName() , Toast.LENGTH_SHORT).show();
        }
    };
    public SkmDatePickerPopup.SkmDatePickerPopupOnClickListener skmDatePickerPopupOnClickListener=new  SkmDatePickerPopup.SkmDatePickerPopupOnClickListener(){

        @Override
        public void myOnClick(int year, int month, int day, int hour, int minute, View v,View vv) {
            skmDatePickerPopup.dismiss();
            Toast.makeText(MainActivity.this,"您选择的日期："+year+"年  "
                    +month+"月  "+day+"日"+ hour+"时 "+minute+"分钟",Toast.LENGTH_SHORT).show();
        }

    };






}
